package com.eastseeway.radioproject;

import android.util.Log;

import com.eastseeway.radioproject.entities.BaseResponse;
import com.eastseeway.radioproject.entities.ImgResponse;
import com.eastseeway.radioproject.retrofit.RetrofitClient;

import java.io.File;
import java.net.HttpURLConnection;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LongConnectionManager {

    private final ScheduledExecutorService scheduledExecutor;//线程池 同一管理保证只有一个
    private int time = 0;
    private boolean allowRequest = true;

    public LongConnectionManager() {
        scheduledExecutor = Executors.newSingleThreadScheduledExecutor();//初始化线程
    }

    private static final class InstanceHolder {
        static final LongConnectionManager instance = new LongConnectionManager();
    }

    public static LongConnectionManager getInstance(){
        return InstanceHolder.instance;
    }

    public void startRequestTask(){
        scheduledExecutor.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                Log.e("12121", "scheduleWithFixedDelay ");
                if (allowRequest) {
                    request();
                }

            }
        }, 0, 5, TimeUnit.SECONDS);
    }


    private void upload(){
        File file = new File("");
        RequestBody body = RequestBody.create(MediaType.parse("multipart/form-data"),file);
        MultipartBody.Part formData = MultipartBody.Part.createFormData("", "", body);
    }


    private void request(){
    }

}
